﻿using System;
namespace example
{
    class Program
    {
        static void Main(string[] args)
        {

            DateTime beforeDT = System.DateTime.Now;


            //上午工作时间段
            Matrix m1 = TimeToMatrix("08:30","12:00");
            //下午工作时间段(不可和上午重叠)
            m1 += TimeToMatrix("14:30","18:00");
            //实际工作的时间段
            Matrix m2 = TimeToMatrix("00:00","11:05");

            Matrix m3 = m1+m2; //矩阵相加
            int minute = 0;  //有效工作分钟
            for(int i = 0;i < 24; i++)
            {
                for(int j = 0; j < 60; j++)
                {
                    if(m3[i,j]>1) //重叠部分
                    {
                        minute ++;
                    }
                }
            }

            DateTime afterDT = System.DateTime.Now;
            TimeSpan dt = afterDT.Subtract(beforeDT);
            Console.WriteLine("程序耗时:'{0}'秒", dt);
            Console.WriteLine(minute);
        }
    
    
        static Matrix TimeToMatrix(string strStarTime, string strEndTime, double n=1)
        {
            Matrix matrix = new Matrix(24,60);
            matrix.SetValue(0);
            var tempTimeArray = strStarTime.Split(':');
            int hourStar = int.Parse(tempTimeArray[0]);
            int minuteStar = int.Parse(tempTimeArray[1]);
            tempTimeArray = strEndTime.Split(':');
            int hourEnd = int.Parse(tempTimeArray[0]);
            int minuteEnd = int.Parse(tempTimeArray[1]);
            for(int i = hourStar;i <= hourEnd; i++)
            {
                for(int j = 0; j < 60; j++)
                {
                    if(i==hourEnd && j==minuteEnd)
                    {
                        break;
                    }
                    if(i==hourStar && j<minuteStar)
                    {
                        continue;
                    }
                    matrix[i,j] = n;
                }
            }
            return matrix;
        }
    }


}
